package shoppingmall.reception.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import shoppingmall.reception.dto.PageBean;
import shoppingmall.reception.dto.Result;
import shoppingmall.reception.service.ProductClassificationService;


/**
 * 商品分类相关-控制层
 */
@Slf4j
@RestController
public class ProductClassification {
    //商品分类服务层实例
    @Autowired
    private ProductClassificationService productClassificationService;

    /**
     * 获取所有的商品分类
     */
    @GetMapping("/reception/classification")
    public Result getAllProductClassification () {
        log.info("查询商品的所有分类信息");
        //调用服务层相关方法
        PageBean pageBean = productClassificationService.getAllProductClassification();
        if(pageBean.getTotal() == 0) {
            return Result.success("未查询到商品分类数据!");
        }
        return Result.success(pageBean);
    }

    /**
     * 查询所有当前分类下的商品信息
     */
    @GetMapping("/reception/classification/product")
    public Result getAllProductClassificationIncludeProductInfo () {
        log.info("查询所有当前分类下的商品信息");
        //调用服务层相关方法
        PageBean pageBean = productClassificationService.getAllProductClassificationIncludeProductInfo();
        if(pageBean.getTotal() == 0) {
            return Result.success("未查询到当前分类下的商品信息!");
        }
        return Result.success(pageBean);
    }
}
